package io.fredia.femicro.graph.controller;

import java.util.Collection;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.fredia.femicro.graph.domain.Movie;
import io.fredia.femicro.graph.service.MovieService;

@RestController
@RequestMapping("/")
public class MovieController {

	@Autowired
	private MovieService movieService;

	@GetMapping("/movie")
	public Movie findByTitle(@RequestParam String title) {
		return movieService.findByTitle(title);
	}

	@GetMapping("/movies")
	public Collection<Movie> findByTitleLike(@RequestParam String title) {
		return movieService.findByTitleLike(title);
	}

	@GetMapping("/graph")
	public Map<String, Object> graph(@RequestParam(value = "limit", required = false) Integer limit) {
		return movieService.graph(limit == null ? 100 : limit);
	}

	@GetMapping("/addRelation")
	public Map<String, Object> addRelation() {
		movieService.addRelation();
		return null;
	}

}
